//
//  MainTabBar.swift
//

import UIKit

class MainTabBar: UITabBar {

    private lazy var vipView: UIImageView = {
        let view = UIImageView()
        view.image = "tabbar_middlebulge_backImg".image
        return view
    }()
    
    private lazy var vipImageView: UIImageView = {
        let view = UIImageView()
        view.image = "tabbar_vip_normal".image
        view.contentMode = .scaleAspectFit
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        isTranslucent = false
        backgroundImage = UIImage.imageWithColor(color: UIColor.white, size: CGSize(width: UIScreen.width, height: 49))
        shadowImage = UIImage.imageWithColor(color: UIColor(hex: "#F4F4F4"), size: CGSize(width: 1.0, height: 0.5))
        addSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        vipView.center = CGPoint(x: center.x, y: 20)
    }
    
    private func addSubviews() {
        vipView.frame = CGRect(x: 0, y: 0, width: (UIScreen.width - 20) / 5 - 10, height: 61)
        
        addSubview(vipView)
        vipView.addSubview(vipImageView)

        vipImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-16)
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
    }

    func updateVip(_ isSelected: Bool) {
        vipImageView.image = isSelected ? "tabbar_vip_selected".image : "tabbar_vip_normal".image
    }
}
